package com.example.demo.common.http;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public RestResult handleBusinessException(BusinessException e) {
        e.printStackTrace();
        return new RestResult().setCode(RestCode.BUSINESS_EXCEPTION.getCode()).setMsg(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public RestResult<String> handleException(Exception e) {
        e.printStackTrace();
        return new RestResult().setCode(RestCode.FAIL.getCode()).setMsg(e.getMessage());
    }
}
